/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jfinance.UI;

import java.beans.PropertyChangeEvent;
import javax.swing.JPanel;

import jfinance.Account;
import jfinance.View;


/**
 *
 * @author efim
 */
public class AccountBeanForm extends JPanel implements View {

    /**
     * Creates new form AccountBeanForm
     */
    public AccountBeanForm(Account account) {
        super(true);
        initComponents();
        this.account = account; 
        double amount = account.getAmount();
        amountLabel.setText(amount+"");
        nameLabel.setText(account.getName());
        if(amount>0)imageLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("mini_icons/smiley_big_grin.png")));
        if(amount==0)imageLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("mini_icons/smiley_flat.png")));
        if(amount<0)imageLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("mini_icons/smiley_frown.png")));
    }
    private Account account;
    
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        amountLabel = new javax.swing.JLabel();
        imageLabel = new javax.swing.JLabel();

        nameLabel.setFont(new java.awt.Font("Malgun Gothic", 0, 11)); // NOI18N
        nameLabel.setText("Account name");

        amountLabel.setFont(new java.awt.Font("Malgun Gothic", 0, 11)); // NOI18N
        amountLabel.setText("100.0");

        imageLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jfinance/UI/mini_icons/smiley_wink.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(amountLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(imageLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(amountLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel amountLabel;
    private javax.swing.JLabel imageLabel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel nameLabel;
    // End of variables declaration//GEN-END:variables

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        switch(evt.getPropertyName()){
            case Account.UPDATE_AMOUNT_EVENT:
                amountLabel.setText(evt.getNewValue()+"");
                break;
            case Account.UPDATE_NAME_EVENT:
                nameLabel.setText(evt.getNewValue()+"");
                break;
        }
    }
}
